#include<string>
#include<iostream>
#include<unordered_set>
using namespace std;

class Observer {
protected:
	Subject* subject;
public:
	void setSubject(Subject* sub) {
		this->subject = sub;
	}
	virtual void response(const string& msg) = 0;
};

class Subject {
protected:
	unordered_set<Observer*>observers;
public:
	void regist(Observer* observer) {
		observers.insert(observer);
		observer->setSubject(this);
	}
	virtual void notifyAll(const string& msg) = 0;
};

class ConcreteObserver:public Observer {
public:
	void response(const string& msg) {
		std::cout << msg << std::endl;
	}
};

class ConcreteSubject :public Subject {
public:
	void notifyAll(const string& msg) {
		for (auto& po : observers) {
			po->response(msg);
		}
	}
};